package com.itheima.yuanzixing;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantLock;

public class Demo01 {
    public static void main(String[] args) throws InterruptedException {
        ExecutorService pool = Executors.newCachedThreadPool();
        HanZe hanZe = new HanZe();
        for (int i = 0; i < 10; i++) {
            pool.submit(hanZe);
        }
        Thread.sleep(2000);

        System.out.println(hanZe.ai.get());//954  906  1000  1000
        //volatile 887  1000  1000 930

    }

}

class HanZe implements Runnable{
    //volatile int money=0;
    AtomicInteger ai= new AtomicInteger();
   // ReentrantLock lock= new ReentrantLock();
    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            //lock.lock();
           // money++;
            ai.incrementAndGet();
            //lock.unlock();
        }
    }
}

